package com.xxy.partnermatch.easyExcel;

import com.xxy.partnermatch.mapper.UserMapper;
import com.xxy.partnermatch.model.entity.User;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

/**
 * ClassName: InsertUser
 * Package: com.xxy.partnermatch.easyExcel
 * Description: 定时任务执行插入用户
 *
 * @Author 十一
 * @Create 2024/11/18 11:26
 * @Version 1.0
 */
@Component
public class InsertUser {

    @Resource
    private UserMapper userMapper;

    /**
     * 循环插入用户
     */
//    @Scheduled(initialDelay = 5000, fixedRate = Long.MAX_VALUE)
    public void doInsertUser() {
        // 开启定时器
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        // 执行任务
        final int INSERT_NUM = 1000;
        for (int i = 0; i < INSERT_NUM; i++) {
            User user = new User();
            user.setUsername("xuxuanya" + i);
            user.setUserAccount("xiaoya" + i);
            user.setAvatarUrl("https://img2.baidu.com/it/u=3474918508,368034947&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=667");
            user.setProfile("我最爱徐喧雅");
            user.setGender(0);
            user.setUserPassword("1314520520");
            user.setPhone("13145201314");
            user.setEmail("xuxuanya@qq.com");
            user.setUserStatus(0);
            user.setUserRole(0);
            user.setPlanetCode("931");
            user.setTags("['love', 'Java', 'Docker']");
            userMapper.insert(user);
        }
        // 停止定时器
        stopWatch.stop();
        System.out.println(stopWatch.getTotalTimeMillis());
    }

}
